import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { ConfigProvider } from '../../providers/config/config';
import { HttpserviesProvider } from '../../providers/httpservies/httpservies';
import { Http,Jsonp } from '@angular/http';

//自定义页面
import { ProductlistPage } from '../productlist/productlist';

@Component({
  selector: 'page-about',
  templateUrl: 'category.html'
})
export class CategoryPage {

  public cateList = [];
  public shopList = [];
  public ProductlistPage = ProductlistPage;

  constructor(public navCtrl: NavController, public config: ConfigProvider, public httpServices: HttpserviesProvider) {

    //1.0请求一级分类数据
    this.requestCategoryData();

  }

  //请求一级分类数据
  requestCategoryData(){
    this.httpServices.requestData('api/pcate',(data)=>{
      this.cateList = data.result;
      // 默认加载第一个分类的商品数据
      var obj_id = data.result[0]['_id'];
      this.requestShopData(obj_id);
    });
  }

  // 请求对应一级分类的列表数据
  requestShopData(obj_id){
    // http://39.108.159.135/api/pcate?pid=59f1e1ada1da8b15d42234e9
    var request_url = 'api/pcate?pid='+obj_id;
    this.httpServices.requestData(request_url,(data)=>{
      this.shopList = data.result;
    });
  }

  goProductListPage(obj_id){
    //页面条状并且传递参数
    this.navCtrl.push(ProductlistPage,{
      cid : obj_id,
    });
  }

}
